define(
   [
      'dojo/_base/declare',
      'dojo/_base/lang',
      'dstore/Rest',
      'dstore/Trackable',
      'dstore/SimpleQuery'
   ],
   function(declare, lang, Rest, Trackable, SimpleQuery)
   {
      return declare([Rest, Trackable, SimpleQuery],
      {
         useRangeHeaders:     true,
         idProperty:          'Id',
         sortParam:           'sortBy',
         defaultNewToStart:   true,
         headers:             { 'Content-Type': 'application/x-www-form-urlencoded' },
         
         // Constuctor
         constructor:function (args)
         {
            // Call Super
            dojo.safeMixin(this, args);
         },
         postscript: function(args)
         {
            // Called after constructors
            this.inherited(arguments);
         },
         /*
         stringify: function (obj)
         {
            var formData = new FormData();
            // clear out the hidden keys
            var value = JSON.parse(JSON.stringify(obj, function (key, value)
            {
               return value;
            }));
 
            Object.keys(value).forEach(function (key)
            {
               // example for file uploead:
               //formData.append(key, obj.media.file, obj.media.file.name);
               
               formData.append(key, JSON.stringify(obj[ key ]));
            });
 
            return formData;
         },
         */
         get: function (id, options)
         {
            if(!this.restIdProperty)
               return this.inherited(arguments);
            
            // Save off the original target
            var target = this.target;
            
            // Modify the target
            this.target = this.target + '?' + this.restIdProperty + '=';
            
            // Call the backend
            var defReturn = this.inherited(arguments);

            // Put back to original target
            this.target = target;
            
            return defReturn;
         },
         put: function(object, options)
         {
            if(!this.restIdProperty)
               return this.inherited(arguments);

            // Save off the original target
            var target = this.target;

            // Modify the target
            this.target = this.target + '?' + this.restIdProperty + '=';

            // Call the backend
            var defReturn = this.inherited(arguments);

            // Put back to original target
            this.target = target;

            return defReturn;
         },
         remove: function (id, options)
         {
            if(!this.restIdProperty)
               return this.inherited(arguments);

            // Save off the original target
            var target = this.target;

            // Modify the target
            this.target = this.target + '?' + this.restIdProperty + '=';

            // Call the backend
            var defReturn = this.inherited(arguments);

            // Put back to original target
            this.target = target;

            return defReturn;
         }
      });
   }
);

